﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Studentperformancemanagement
{
    public partial class Form2 : Form
    {
        bool addorupdatin;//true(添加)false（修改）
        public Form2()
        {
            InitializeComponent();
            addorupdatin = true;
        }
        public int ids;
        public Form2(int id,string name,int age, int score)
        {
            InitializeComponent();
            addorupdatin = false;
            ids = id;
            textBox1.Text = name;
            textBox2.Text = age.ToString();
            textBox3.Text = score.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" && textBox2.Text == "" && textBox3.Text == "")
            {
                MessageBox.Show("输入数据不允许为空");
            }
            else
            {
                if (addorupdatin)
                {
                    string sql = string.Format("INSERT INTO Students (Name,Age,Score) VALUES ('{0}','{1}','{2}')", textBox1.Text, textBox2.Text, textBox3.Text);
                    int line = Class1.Adddeletemodify(sql);
                    if (line > 0)
                    {
                        MessageBox.Show("添加成功");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("添加失败");
                    }
                }
                else
                {
                    string sql = string.Format("UPDATE Students SET Name='{0}',Age='{1}',Score='{2}' WHERE Id='{3}'", textBox1.Text, textBox2.Text, textBox3.Text,ids);
                    int line = Class1.Adddeletemodify(sql);
                    if (line > 0)
                    {
                        MessageBox.Show("修改成功");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("修改失败");
                    }

                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
